package com.ftg.learn.chapter04;

/**
 * 电脑类石头剪刀布
 *
 * @author lijiaxin
 * @version 1.0
 * @date 2023/6/10 15:10
 */

public class computer {


    private String player;

    public void setPlayer(String player) {
        this.player = player;
    }

    public String getPlayer() {
        return this.player;
    }

    /**
     * 随机生成1 -3数
     *
     * @return
     */

        //(int)(Math.random()* (最大値-小値+1))+ 最小
        private int createNum() {
            return (int) (Math.random() * 3) + 1;
        }

        /**
         * 文本提示了
         *
         * @param i
         * @return
         */

            private String getMessWithNum(int i) {
                switch (i) {
                    case 1:
                        return "剪子";
                    case 2:
                        return "石头";
                    case 3:
                        return "布";
                    default:
                        return "错了";
                }
            }

            public void winner(computer c) {
                int otherComputerInt = c.createNum();
                int myselfInt = this.createNum();

                String otherComMess = c.getMessWithNum(otherComputerInt);
                String myselfMess = c.getMessWithNum(myselfInt);

                if (myselfInt == 1 && otherComputerInt == 3) {
                    System.out.printf("玩家%s出了一个%s,玩家%s出一个%s,恭喜玩家%s胜出\n", c.getPlayer(), otherComMess, this.getPlayer(), myselfMess, this.getPlayer());
                } else if (myselfInt == 3 && otherComputerInt == 1) {
                    System.out.printf("玩家%s出了一个%s,玩家%s出一个%s,恭喜玩家%s胜出\n", c.getPlayer(), otherComMess, this.getPlayer(), myselfMess, c.getPlayer());
                } else if (otherComputerInt > myselfInt) {
                    System.out.printf("玩家%s出了一个%s,玩家%s出一个%s,恭喜玩家%s胜出\n", c.getPlayer(), otherComMess, this.getPlayer(), myselfMess, c.getPlayer());
                }  else if (myselfInt > otherComputerInt) {
                    System.out.printf("玩家%s出了一个%s,玩家%s出一个%s,恭喜玩家%s胜出\n", c.getPlayer(), otherComMess, this.getPlayer(), myselfMess, this.getPlayer());
                } else {
                    System.out.printf("玩家%s出了一个%s,玩家%s出一个%s,平局\n", c.getPlayer(), otherComMess, this.getPlayer(), myselfMess);
                }

            }

        }